﻿CREATE TABLE [CA].[Contragents] (
    [Id]                   INT           NOT NULL,
    [GId]                  INT           NULL,
    [Name]                 VARCHAR (100) NOT NULL,
    [ShortName]            VARCHAR (20)  NOT NULL,
    [IsSeller]             BIT           CONSTRAINT [DF__Contragen__IsSel__40C49C62] DEFAULT ((0)) NOT NULL,
    [IsCustomer]           BIT           CONSTRAINT [DF__Contragen__IsCus__41B8C09B] DEFAULT ((0)) NOT NULL,
    [IsSertification]      BIT           CONSTRAINT [DF__Contragen__IsSer__42ACE4D4] DEFAULT ((0)) NOT NULL,
    [EMail]                VARCHAR (50)  NULL,
    [Phone]                VARCHAR (50)  NULL,
    [Note]                 VARCHAR (250) NULL,
    [DirectorFIO]          VARCHAR (100) NULL,
    [DirectorPosition]     VARCHAR (50)  NULL,
    [FirmType]             VARCHAR (10)  NULL,
    [JuridicalAddress]     VARCHAR (250) NULL,
    [INN]                  VARCHAR (12)  NULL,
    [KPP]                  VARCHAR (20)  NULL,
    [OKPO]                 VARCHAR (20)  NULL,
    [OKONX]                VARCHAR (20)  NULL,
    [SettlementAccount]    VARCHAR (20)  NULL,
    [Bank]                 VARCHAR (100) NULL,
    [BIK]                  VARCHAR (10)  NULL,
    [CorrespondentAccount] VARCHAR (20)  NULL,
    [ActualAddress]        VARCHAR (250) NULL,
    [Fax]                  VARCHAR (50)  NULL,
    [WebPage]              VARCHAR (50)  NULL,
    [ICQ]                  VARCHAR (50)  NULL,
    [MD]                   DATETIME      CONSTRAINT [DF__Contragents__MD__43A1090D] DEFAULT (getdate()) NOT NULL,
    [MW]                   VARCHAR (50)  CONSTRAINT [DF__Contragents__MW__44952D46] DEFAULT (suser_sname()) NOT NULL,
    [ToDelete]             BIT           DEFAULT ((0)) NOT NULL,
    CONSTRAINT [PK_Contragents] PRIMARY KEY CLUSTERED ([Id] ASC)
);


GO
CREATE NONCLUSTERED INDEX [IX_Contragents_Name]
    ON [CA].[Contragents]([Id] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Contragents_ShortName]
    ON [CA].[Contragents]([Id] ASC);


GO
CREATE NONCLUSTERED INDEX [dta_index_Contragents_5_1364915934__K1_4]
    ON [CA].[Contragents]([Id] ASC)
    INCLUDE([ShortName]);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Продавец', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'IsSeller';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Покупатель', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'IsCustomer';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Организационно-правовая форма организации', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'FirmType';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Расчетный счет', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'SettlementAccount';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Корреспондентский счет', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'CorrespondentAccount';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Фактический адрес', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'ActualAddress';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Признак того, что запись нужно удалить из БД всех подразделений', @level0type = N'SCHEMA', @level0name = N'CA', @level1type = N'TABLE', @level1name = N'Contragents', @level2type = N'COLUMN', @level2name = N'ToDelete';

